<?php
/**
 * Created by PhpStorm.
 * User: Jie
 * Date: 4/13/2016
 * Time: 3:31 PM
 */
class FeedbackController extends \Core_BaseCtl {

    public function indexAction() {
        $this->_view->assign('pageTitle','在线反馈');

    }
    public function addAction() {
        //每个ip每天只能提交一次反馈信息
        $cache_config = $this->config['cache'];
        $cache = Cache_Cache::create($cache_config, Cache_Cache::TYPE_FILE);

        //获取ip地址
        $ip = $_SERVER["REMOTE_ADDR"];
        $check = $cache->get(md5($ip));
        $history = array();
        if ($check) {
            $content = "每天只能提交一次反馈信息";
            $url = "/mobileregister/userinfo";
            $this->redirect(Tools_help::url("redirect/error?c=$content&u=$url"));
            exit;
        } else {
            $history['count'] = 1;
        }

        $feelbackModel = new FeelbackModel();

        if (!empty($_POST)) {
            $cache->set(md5($ip), $history, 3600*24);
            
            $data = $feelbackModel->toArray($_POST);
            $data['addtime'] = time();
            $result = $feelbackModel->insert($data);

            if ($result) {
                $content = "提交反馈成功";
                $url = "/mobileregister/userinfo";
                $this->redirect(Tools_help::url("redirect/index?c=$content&u=$url"));
            } else {
                $content = "每天只能提交一次反馈信息";
                $url = "/mobileregister/userinfo";
                $this->redirect(Tools_help::url("redirect/error?c=$content&u=$url"));
            }
        }
        exit;
    }
}